package com.xszx.order.controller;


import com.xszx.commonutils.R;
import com.xszx.order.service.PayLogService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author 白熊
 * @since 2024-07-26
 *
 * 生成二维码
 */
@RestController
@RequestMapping("/order/payLog")
//@CrossOrigin
@Api(tags = "根据订单生成二维码")
public class PayLogController {

    @Autowired
    private PayLogService payLogService;


    @GetMapping("/createNative/{orderNo}")//获取订单
    public R createNative(@PathVariable("orderNo") String orderNo){
        Map map= payLogService.createNative(orderNo);
        return R.ok().data(map);
    }

    @GetMapping("/queryPayStatus/{orderNo}")
    public R queryPayStatus(@PathVariable("orderNo") String orderNo) {

        //调用查询接口
        Map<String, String> map = payLogService.queryPayStatus(orderNo);
        if (map == null) {//出错
            return R.error().message("支付出错");
        }
        if (map.get("trade_state").equals("SUCCESS")) {//如果成功
            //更改订单状态
            payLogService.updateOrderStatus(map);
            return R.ok().message("支付成功");
        }
        return R.ok().code(25000).message("支付中");
    }

}

